package com.erp.erp_mask.controller;

import com.erp.erp_mask.mapper.TPurchaseMapper;
import com.erp.erp_mask.mapper.TSalesordersMapper;
import com.erp.erp_mask.pojo.TSalesorders;
import com.erp.erp_mask.service.TSalesordersService;
import com.erp.erp_mask.vo.Result;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/pur")
public class salesorderstongController {

    @Resource
    private TSalesordersService tSalesordersService;
    @Resource
    private TSalesordersMapper tSalesordersMapper;
    @Resource
    private TPurchaseMapper tPurchaseMapper;

    @GetMapping("/sellrep")
    public ModelAndView modelAndView() {
        return new ModelAndView("/pur/salesorderstong");
    }


    @GetMapping("/tong")
    public List<Object> tong() {
        List<Object> objects = new ArrayList<>();
        List<TSalesorders> list = tSalesordersService.tongOrders();
        for (TSalesorders cc : list) {
            int dd = cc.getTotalOrders();
            String date = cc.getOrderMonth();
            objects.add(new Object() {
                public int value = dd;
                public String name = date;

                @Override
                public String toString() {
                    return "{" + dd + "," + date + "}";
                }
            });
        }
        return objects;
    }

    @GetMapping("/searchlist")
    public Result searchlist() {
        return Result.success(tSalesordersMapper.searchlist());
    }
    @GetMapping("/max")
    public Result searchmax(){
        return Result.success(tPurchaseMapper.searlist());
    }

}
